package com.yi.suprise.view;

import android.graphics.Rect;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.yi.suprise.R;
import com.yi.suprise.adapter.MainAdapter;
import com.yi.suprise.modle.MainModle;
import com.yi.suprise.presenter.MainPresenter;
import com.yi.suprise.util.DensityUtil;
import com.yi.yilib.base.AppActivity;
import com.yi.yilib.base.BaseFragment;
import com.yi.yilib.mvp.YiView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements YiView<ArrayList<MainModle>>,View.OnClickListener{
    private MainPresenter mainPresenter;

    private MainAdapter adapter;

    @BindView(R.id.RecyclerView)
    RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        mainPresenter = new MainPresenter(this);
        mainPresenter.onCreate();
        initView();
    }

    private void initView() {
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
                super.getItemOffsets(outRect, view, parent, state);
                outRect.bottom = DensityUtil.dp2px(MainActivity.this,1);
            }
        });
    }


    @Override
    public void onClick(View v) {
        mainPresenter.performOnClick(v.getId());
    }

    @Override
    public void setData(ArrayList<MainModle> mainModles) {
        adapter = new MainAdapter(this,mainModles);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void noData() {

    }

    @Override
    public void error() {

    }
}
